﻿using System;
using System.Collections.Generic;
using System.Text;

using HyEduOnline.Entities;
using HyEduOnline.Data;
namespace HyEduOnline.Server.Teacher
{
	/// <summary>
	///		此用于处理表对象 'tb_TestLib' 
	/// </summary>
	/// <remarks>
	/// 	此结构由代码由TMS使用代码生成器书写生成，请不要直接修改.
	///注意:此代码可能和同名的视图生成一个完整对象
	/// </remarks>
	

	
	public partial class TestLibBaseDAO
	{
		
	#region 表生成代码
		protected int TotalCount = -1;
		
		
		/// <summary>
       
		
		/// <summary>
        /// 取所有的对象,例如TList<???>
        /// </summary>
        /// <returns></returns>
		[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select, true)]
        public  TList<TbTestLib> GetAll()
        {
            return DataRepository.Provider.TbTestLibProvider.GetAll();
        }

		/// <summary>
        /// 通过id来取对象
        /// </summary>
        /// <param name="id">对象的ID</param>
        /// <returns></returns>
		[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select, false)]
        public TbTestLib GetByID(int id)
        {
            return DataRepository.Provider.TbTestLibProvider.GetById(id);
        }

        /// <summary>
        /// 条件查询分页
        /// </summary>
        /// <param name="whereClause">条件</param>
        /// <param name="startRowIndex">起始值</param>
        /// <param name="maximumRows">每页的最大值</param>
        /// <returns></returns>
        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select, false)]
        public  TList<TbTestLib> GetByPage(string whereClause, int startRowIndex, int maximumRows)
        {

            return DataRepository.Provider.TbTestLibProvider.GetPaged(whereClause, "ID", (int)startRowIndex / maximumRows, maximumRows, out TotalCount);

        }
		
		 /// <summary>
        ///支持Ext的分页查询,表
        /// </summary>
        /// <param name="whereClause">查询条件</param>
        /// <param name="start">起始位置</param>
        /// <param name="limit">最大条数</param>
        /// <param name="sort">排序列</param>
        /// <param name="dir">排序方向("DESC","ASC")</param>
        /// <param name="count">取得记录数</param>
        /// <returns>TList<???></returns>
		[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select, false)]
        public  TList<TbTestLib>  GetByPage(string whereClause, int start, int limit, string sort, string dir, out int count)
        {
            string sOrder = "";
            if (! String.IsNullOrEmpty(sort ) && sort.ToUpper() != "ID")
            {
                sOrder = sort.Insert(1, "_") + " " + dir;
            }
            else
            {
                 if (sort != null && sort.ToLower() == "id") sOrder = sort + " " + dir;
            }
			
            return DataRepository.Provider.TbTestLibProvider.GetPaged(whereClause, sOrder, (int)start / limit, limit, out count);
        }
		
		
		
        /// <summary>
        /// 分页查询计数
        /// </summary>
        /// <param name="whereClause">查询调价</param>
		/// <param name="startRowIndex">起始值</param>
        /// <param name="maximumRows">每页的最大值</param>
        /// <returns></returns>
        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select, false)]
        public int GetCount(string whereClause, int startRowIndex, int maximumRows)
        {
            if (TotalCount != -1)
            {
                return TotalCount;
            }
            else
            {
                DataRepository.Provider.TbTestLibProvider.GetTotalItems(whereClause, out TotalCount);
                return TotalCount;
            }
        }
		
		
		
		
		/// <summary>
        /// 更新对象，传入的是一个对象
        /// </summary>
        /// <param name="item">需要更新的对象</param>
        /// <returns></returns>
		[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Update, true)]
        public bool Update(TbTestLib item)
        {
            return DataRepository.Provider.TbTestLibProvider.Update(item);
        }
		
		/// <summary>
        /// 更新对象，传入的是一个Tlist对象
        /// </summary>
        /// <param name="items">需要更新的TList对象</param>
        /// <returns></returns>
		[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Update, false)]
        public int Update(TList<TbTestLib> items)
        {
            return DataRepository.Provider.TbTestLibProvider.Update(items);
        }
		
		
		
		/// <summary>
        /// 更新对象，传入的是此对象的多个属性，属性个数为  15
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
		[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Update, false)]
        public bool Update(
		System.Int32? ICousreId, System.String SCourseCode, System.Int32? IProblemType, 
			System.String STitle, System.String SContent, System.Int32? IStuOpen, System.String SAnswer, 
			System.Int32? ITeaCatalog, System.Int32? IHardLevel, System.Int32? IDiffLevel, System.String SPointers, 
			System.String SKeyWords, System.String SCharpter, System.Int64? IGroupId, System.String SAnalysis, 
			System.Int64 Id
		)
        {
			
			TbTestLib item =new TbTestLib();
			
			
			

			item.ICousreId = ICousreId;
			item.SCourseCode = SCourseCode;
			item.IProblemType = IProblemType;
			item.STitle = STitle;
			item.SContent = SContent;
			item.IStuOpen = IStuOpen;
			item.SAnswer = SAnswer;
			item.ITeaCatalog = ITeaCatalog;
			item.IHardLevel = IHardLevel;
			item.IDiffLevel = IDiffLevel;
			item.SPointers = SPointers;
			item.SKeyWords = SKeyWords;
			item.SCharpter = SCharpter;
			item.IGroupId = IGroupId;
			item.SAnalysis = SAnalysis;
			
			
			item.Id = Id;
			
            return DataRepository.Provider.TbTestLibProvider.Update(item);
        }
		
		
		/// <summary>
        /// 通过ID来删除对象
        /// </summary>
        /// <param name="id">对象ID</param>
        /// <returns></returns>
        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Delete, true)]
        public int Del(string ids)
        {
		
			TList<TbTestLib> tmpList= GetByPage("id in ("+ids+")",0,int.MaxValue);
			

            return Del(tmpList);

        }
		
		
		/// <summary>
        /// 通过ID来删除对象
        /// </summary>
        /// <param name="id">对象ID</param>
        /// <returns></returns>
        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Delete, true)]
        public bool Del(int id)
        {

            return DataRepository.Provider.TbTestLibProvider.Delete(id);

        }
		
		/// <summary>
        /// 通过对象删除记录
        /// </summary>
        /// <param name="item">对象</param>
        /// <returns></returns>
        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Delete, false)]
        public bool Del(TbTestLib item)
        {

            return DataRepository.Provider.TbTestLibProvider.Delete(item);

        }
		
		/// <summary>
        /// 通过对象删除记录
        /// </summary>
        /// <param name="items">需删除的TList对象</param>
        /// <returns></returns>
        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Delete, false)]
        public int Del(TList<TbTestLib> items)
        {

            return DataRepository.Provider.TbTestLibProvider.Delete(items);

        }
		
		
		/// <summary>
        /// 插入一个对象
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
		 [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Insert, true)]
        public bool Insert(TbTestLib item)
        {
            return DataRepository.Provider.TbTestLibProvider.Insert(item);
        }
		
		/// <summary>
        /// 插入一个TList对象
        /// </summary>
        /// <param name="items"></param>
        /// <returns></returns>
		 [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Insert, false)]
        public int Insert(TList<TbTestLib> items)
        {
            return DataRepository.Provider.TbTestLibProvider.Insert(items);
        }
        
		/// <summary>
        /// 更具条件查找
        /// </summary>
        /// <param name="whereClause">需要查找的条件</param>
        /// <returns>TList对象</returns>
        public TList<TbTestLib> GetByCondition(string whereClause)
        {
            return DataRepository.Provider.TbTestLibProvider.Find(whereClause);
        }
		
		


#endregion 表生成代码

#region 兼容代码



		 /// <summary>
        ///兼容查询
        /// </summary>
        /// <param name="whereClause">查询条件</param>
        /// <param name="start">起始位置</param>
        /// <param name="limit">最大条数</param>
        /// <param name="sort">排序列</param>
        /// <param name="dir">排序方向("DESC","ASC")</param>
        /// <param name="count">取得记录数</param>
        /// <returns>TList<???></returns>
		
        public  TList<TbTestLib>  getByPageDataBase( int start, int limit, string sort,string whereClause, out int count)
        {
		///(0, 10000, "I_Level ASC,I_Group ASC,ID ASC", "I_Type=1 and id<>1", out count);
            string sOrder = "";
            string[] sortTmps=sort.Split(' ');

            if (!String.IsNullOrEmpty(sort) && sortTmps[0].ToUpper() != "ID")
            {

                sOrder = sort.Insert(1, "_") ;
            }
            else
            {
                 if (sort != null && sort.ToLower() == "id") sOrder = sort + " " ;
            }
			
            return DataRepository.Provider.TbTestLibProvider.GetPaged(whereClause, sOrder, start , limit, out count);
        }


 /// 取所有的对象,例如TList<???>
        /// </summary>
        /// <returns></returns>
		[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select, true)]
        public  TList<TbTestLib> findAll()
        {
            return DataRepository.Provider.TbTestLibProvider.GetAll();
        }
		

		 public  TList<TbTestLib> findByProperty(String propertyName, Object value)
        {
            TList<TbTestLib> tmpList = new TList<TbTestLib>();
            try
            {

                string whereC = "";
				 string FirC=propertyName.Substring(0,1);
                if (FirC != "I" || FirC != "F")
                {
                
                    value="'"+value.ToString()+"'";
                }
				
                if (!String.IsNullOrEmpty(propertyName) && propertyName.ToUpper() != "ID")
                {
                    whereC = propertyName.Insert(1, "_") + "= " + value.ToString();
                }
                else
                {
                    whereC = propertyName + "= " + value.ToString();
                }

              
                tmpList = GetByPage(whereC,0,int.MaxValue);
                return tmpList;
            }
            catch (Exception re)
            {
                throw re;
            }
        }//end for findByProperty
		
		
		
		  /*
       *get the Object through ICousreId
       */
	public IList<TbTestLib> findByICousreId(Object _ICousreId)
        {
            return findByProperty("ICousreId",_ICousreId);
         }
		
		
		  /*
       *get the Object through SCourseCode
       */
	public IList<TbTestLib> findBySCourseCode(Object _SCourseCode)
        {
            return findByProperty("SCourseCode",_SCourseCode);
         }
		
		
		  /*
       *get the Object through IProblemType
       */
	public IList<TbTestLib> findByIProblemType(Object _IProblemType)
        {
            return findByProperty("IProblemType",_IProblemType);
         }
		
		
		  /*
       *get the Object through STitle
       */
	public IList<TbTestLib> findBySTitle(Object _STitle)
        {
            return findByProperty("STitle",_STitle);
         }
		
		
		  /*
       *get the Object through SContent
       */
	public IList<TbTestLib> findBySContent(Object _SContent)
        {
            return findByProperty("SContent",_SContent);
         }
		
		
		  /*
       *get the Object through IStuOpen
       */
	public IList<TbTestLib> findByIStuOpen(Object _IStuOpen)
        {
            return findByProperty("IStuOpen",_IStuOpen);
         }
		
		
		  /*
       *get the Object through SAnswer
       */
	public IList<TbTestLib> findBySAnswer(Object _SAnswer)
        {
            return findByProperty("SAnswer",_SAnswer);
         }
		
		
		  /*
       *get the Object through ITeaCatalog
       */
	public IList<TbTestLib> findByITeaCatalog(Object _ITeaCatalog)
        {
            return findByProperty("ITeaCatalog",_ITeaCatalog);
         }
		
		
		  /*
       *get the Object through IHardLevel
       */
	public IList<TbTestLib> findByIHardLevel(Object _IHardLevel)
        {
            return findByProperty("IHardLevel",_IHardLevel);
         }
		
		
		  /*
       *get the Object through IDiffLevel
       */
	public IList<TbTestLib> findByIDiffLevel(Object _IDiffLevel)
        {
            return findByProperty("IDiffLevel",_IDiffLevel);
         }
		
		
		  /*
       *get the Object through SPointers
       */
	public IList<TbTestLib> findBySPointers(Object _SPointers)
        {
            return findByProperty("SPointers",_SPointers);
         }
		
		
		  /*
       *get the Object through SKeyWords
       */
	public IList<TbTestLib> findBySKeyWords(Object _SKeyWords)
        {
            return findByProperty("SKeyWords",_SKeyWords);
         }
		
		
		  /*
       *get the Object through SCharpter
       */
	public IList<TbTestLib> findBySCharpter(Object _SCharpter)
        {
            return findByProperty("SCharpter",_SCharpter);
         }
		
		
		  /*
       *get the Object through IGroupId
       */
	public IList<TbTestLib> findByIGroupId(Object _IGroupId)
        {
            return findByProperty("IGroupId",_IGroupId);
         }
		
		
		  /*
       *get the Object through SAnalysis
       */
	public IList<TbTestLib> findBySAnalysis(Object _SAnalysis)
        {
            return findByProperty("SAnalysis",_SAnalysis);
         }
		
		
#endregion 兼容代码
#region 自定义代码


		
#endregion 自定义代码

	}
}